<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录页面</title>
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/login.css">
    <script src="js/jquery.min.js"></script>
</head>
<body>
    <!--导航栏-->
    <div class="nav">
        <img src="image/头像.jpg" alt="">
        <span class="title">ybo的博客系统</span>
        <!--spance用来占位-->
        <span class="spance"></span>
        <!--按钮-->
        <a href="blog_list.html">主页</a>
        <a href="blog_edit.html">写博客</a>
        <a href="javascript:logout()">注销</a>
    </div>

    <!--构造页面版心-->
    <div class="login-container">
        <div class="login-dialog">
            <h3>登录</h3>
            <div class="row">
                <span>用户名</span>
                <input type="text" id="username" name="username" placeholder="请输入用户名"/>
            </div>
            <div class="row">
                <span>密码</span>
                <input type="password" id="password" name="password" placeholder="请输入密码"/>
            </div>
            <div class="row"> 
                <input type="button" value="登录" id="submit" onclick="mysub()">
                <span> </span>
                <input type="button" onclick='location.href=("register.html")' value="注册" id="rsubmit">
            </div>
        </div>
    </div>

    <script>
        function mysub(){
            // 1. 非空校验
            var username = jQuery("#username");
            var password = jQuery("#password");
            if(jQuery.trim(username.val())==""){
                console.log("哈哈哈哈哈");
                alert("请先输入用户名！");
                console.log("呵呵呵");
                username.focus();
                return false;
            }
            if(jQuery.trim(password.val())==""){
                alert("请先输入密码！");
                password.focus();
                return false;
            }
            jQuery.ajax({
                url:"login",
                type:"POST",
                data:{"username":username.val(),"password":password.val()},
                success:function(result){
                    if(result!=null && result.data==true){
                        location.href = "blog_list.html"; 
                    }else{
                        alert("抱歉：用户名或者密码输入错误，请重写输入！");
                    }
                }
            });
        }
    </script>

</body>
</html>